package com.tro.common.util.mybatis;

import java.util.List;

public class SqlHandler {
	public String getwhereString(List<Condition> list) {
		StringBuffer sb = new StringBuffer();
		if (list.size() <= 0) {
			return "";
		} else {
			sb.append(" where 1=1 and");
			for (Condition item : list) {
				sb.append(" " + item.getName());
				switch (item.getOpertion()) {
				case Equal:
					sb.append(" = ");
					break;
				case UnEqual:
					sb.append(" <> ");
					break;
				case GreatThan:
					sb.append(" >= ");
					break;
				case LessThan:
					sb.append(" <= ");
					break;
				case Like:
					sb.append(" like ");
					break;
				}
				sb.append(item.getValue());
			}
			if (sb.toString().endsWith("and")) {
				sb.delete(sb.length() - 3, sb.length());
			}
			return sb.toString();
		}
	}
}
